<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<div class="modal-dialog ms-modal-dialog">
  <div class="modal-content">

    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal">
        <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
      </button>
      <h4 class="modal-title">修改用户信息</h4>
    </div>

    <form class="form-horizontal ms-form form-personal-info" method="POST" action="${ctx.host}/principals/${principal.id}" data-validate="true">

      <input type="hidden" name="_method" value="PATCH" /> 
      <input type="hidden" name="principalId" value="${principal.id}" />

      <div class="modal-body">

        <div class="form-group  ms-form-group">
          <label class="control-label col-xs-3">用户名：</label>
          <div class="col-xs-8">
            <input type="text" class="form-control" name="username" value="${principal.username}" readonly="readonly" />
          </div>
        </div>

        <div class="form-group  ms-form-group">
          <label class="control-label col-xs-3"><span class="text-red">*</span>姓名：</label>
          <div class="col-xs-8">
            <input type="text" class="form-control" name="name" value="${principal.name}" data-validate="required" tabindex="5" placeholder="姓名" autocomplete="off"/>
          </div>
        </div>

        <div class="form-group  ms-form-group">
          <label class="control-label col-xs-3"><span class="text-red">*</span>手机：</label>
          <div class="col-xs-8">
            <input type="text" class="form-control" name="mobile" value="${principal.mobile}" data-validate="required|mobile" tabindex="4" placeholder="请输入手机" autocomplete="off" />
          </div>
        </div>

        <c:if test="${currentPrincipal.admin}">
          <div class="form-group ms-form-group">
            <label class="col-xs-3 control-label"><span class="text-red">*</span>角色：</label>
            <div class="col-xs-8">
              <select name="authority" class="select2  form-control" data-validate="required" tabindex="3">
                <c:forEach var="role" items="${persist.roles}">
                  <option></option>
                  <option value="${role.code}" ${principal.authority == role.code ? 'selected' : '' }>${role.description}</option>
                </c:forEach>
              </select>
            </div>
          </div>
          <div class="form-group ms-form-group">
            <label class="col-xs-3 control-label"><span class="text-red">*</span>所在分区：</label>
            <div class="col-xs-8">
              <select name="districtId" class="select2  form-control" data-validate="required" tabindex="3">
                <option></option>
                <c:forEach var="district" items="${persist.districts}">
                  <option value="${district.id}"  ${principal.district.id == district.id ? 'selected' : '' }>${district.name}</option>
                </c:forEach>
             </select>
            </div>
          </div>
        </c:if>

      <div class="modal-footer ms-modal-footer">
        <button type="submit" class="btn ms-btn btn-primary">确定</button>
        <button type="button" class="btn ms-btn ms-btn-gary" data-dismiss="modal">取消</button>
      </div>
      </div>
    </form>
  </div>
</div>

<script type="text/javascript">
    $(document).ready(function() {
        $('select[name="authority"]').select2({
            theme : "classic",
            placeholder : '请选择角色',
            minimumResultsForSearch : -1,
            allowClear : true
        });
        $('select[name="districtId"]').select2({
            theme : "classic",
            placeholder : '请选择分区',
            minimumResultsForSearch : -1,
            allowClear : true
        });
    })
</script>